<template>
	<web-view v-if="path" class="container" :src="path"></web-view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onLoad,
		onShareAppMessage,
		onShow
	} from "@dcloudio/uni-app";
	const path = ref("");
	const name = ref("");
	onLoad((option) => {
		console.log(option, 14);
		path.value = option.path;
		name.value = option.name;
	});
	onShareAppMessage(() => {
		return {
			title: name.value, // 可自定义
			path: `/chanPin/pages/fileDetail?path=${path.value}`,
			imageUrl: "/static/PDF.png",
		};
	});
	onShow(() => {
		// showPdf()
	});

	function showPdf() {
		uni.showLoading({
			title: "加载中",
		});
		// #ifdef APP-PLUS || MP-WEIXIN
		uni.downloadFile({
			url: path.value,
			success: (res) => {
				uni.hideLoading();
				// #ifdef APP-PLUS
				uni.openDocument({
					filePath: res.tempFilePath,
					fileType: "pdf",
				});
				// #endif

				// #ifdef MP-WEIXIN
				wx.openDocument({
					filePath: res.tempFilePath,
					fileType: "pdf",
				});
				// #endif
			},
			fail: (err) => {
				uni.hideLoading();
				uni.showToast({
					title: "打开失败",
					icon: "none",
				});
				console.error(err);
			},
		});
		// #endif
	}
</script>

<style scoped>
	.container {
		width: 100%;
		height: 100vh;
		background-color: aqua;
	}
	.dingwei{
		position: absolute;
		bottom: 200rpx;
		left: 50%;
		background-color: aquamarine;
	}
</style>